<?php
function countWhere($input = 1, $operator = '==', $where = 1)
 {
     $input = is_array($input) ? $input : (array)$input;
     $operator = !in_array($operator, array('<','>','<=', '>=','==', '!=')) ? '==' : $operator;
     $i = 0;
     foreach($input as $current)
     {
         $match = null;
         eval('$match = (bool)("'.$current.'"'.$operator.'"'.$where.'");');
         $i = $match ? $i+1 : $i;
     }
     return $i;
	 unset($current);
 }

function inWhere($input = 1, $where = 1) //input =array, where =pembanding
{
$input = is_array($input) ? $input : (array)$input;
$i=1;$j=1;
	foreach($input as $current)
	{
	if ($current==$where)
	{/*echo "[".$i."]";*/
	$j=$i;}
	$i++;
	}
return $j;
unset($current);
}
?>

<?php
//echo "start<br/>";for ($a=1;$a<=30;$a++){$angka[$a]=rand(1,35);echo $angka[$a]." ; ";}
//$b=count($angka);echo "<br/>".$b."<br/>";

function quickCount($angka)
{
$unik = array_unique($angka);	//dapetin angka unik
$hitung = count($unik);			//hitung ada berapa angka unik
foreach ($unik as &$value) {	//rubah angka unik; array() => array[]
    $unik2[]=$value;
	//echo $value.";";
}unset($value);
$jumlah = array_count_values($angka);	//hitung banyaknya tiap angka unik
//print_r($jumlah);
foreach ($jumlah as &$value) {	//rubah banyaknya angka unik; array() => array[]
    $jumlah2[]=$value;
	//echo $value.";";
}unset($value);
//print_r($unik);
//echo "<br/>".$hitung."<br/>";
for ($a=0;$a<$hitung;$a++)
{
if ($jumlah2[$a]==1)
{$hh[$a]=2;}
elseif ($jumlah2[$a]==2)
{$hh[$a]=1;}
else {$hh[$a]=4;}
}
$fit_slot_tot=array_sum($hh);

for ($a=0;$a<$hitung;$a++){
if ($unik2[$a]<=10){ $fit_efek[$a]=($jumlah2[$a])*1;}
elseif ($unik2[$a]<=20){ $fit_efek[$a]=($jumlah2[$a])*2;}
elseif ($unik2[$a]<=30){ $fit_efek[$a]=($jumlah2[$a])*3;}
}
$fit_efek_tot=array_sum($fit_efek);

$fit_total=round(1/($fit_slot_tot+$fit_efek_tot), 5);
return $fit_total;

/*echo "<table border='1'>";	//Cara 1
echo "<tr><td></td><td>count</td><td>fitnes-slot</td><td>fitnes-efek-slot</td></tr>";
for ($a=0;$a<$hitung;$a++){
echo "<tr><td>".$unik2[$a]."</td>";	//angka
echo "<td>".$jumlah2[$a]."</td>";	//count
echo "<td>".$hh[$a]."</td>";	//fitnes
echo "<td>".$fit_efek[$a]."</td></tr>";}
echo "<tr><td>".$fit_slot_tot."</td><td>".$fit_efek_tot."</td><td>".$fit_total."</td></tr>";
echo "</table>";*/


/*echo "\n<table border='1'>";	//cara 2, kl pk ini uncomment fungsi 1...
for ($a=0;$a<$hitung;$a++)
{
echo "<tr><td>". $unik2[$a]."</td>";
echo "<td>".countwhere($angka, '==', $unik2[$a])."</td></tr>";
}
echo "</table>";*/
}

function cekQCount($angka){
$unik = array_unique($angka);	//dapetin angka unik
$hitung = count($unik);			//hitung ada berapa angka unik
foreach ($unik as &$value) {	//rubah angka unik; array() => array[]
    $unik2[]=$value;
}unset($value);
$jumlah = array_count_values($angka);	//hitung banyaknya tiap angka unik
foreach ($jumlah as &$value) {	//rubah banyaknya angka unik; array() => array[]
    $jumlah2[]=$value;
}unset($value);
for ($a=0;$a<$hitung;$a++)
{
if ($jumlah2[$a]==1)
{$hh[$a]=2;}
elseif ($jumlah2[$a]==2)
{$hh[$a]=1;}
else {$hh[$a]=4;}
}
$fit_slot_tot=array_sum($hh);

for ($a=0;$a<$hitung;$a++){
if ($unik2[$a]<=10){ $fit_efek[$a]=($jumlah2[$a])*1;}
elseif ($unik2[$a]<=20){ $fit_efek[$a]=($jumlah2[$a])*2;}
elseif ($unik2[$a]<=30){ $fit_efek[$a]=($jumlah2[$a])*3;}
}
$fit_efek_tot=array_sum($fit_efek);

$fit_total=round(1/($fit_slot_tot+$fit_efek_tot), 5);

echo "<table border='1'>";	//Cara 1
echo "<tr><td></td><td>count</td><td>fitnes-slot</td><td>fitnes-efek-slot</td></tr>";
for ($a=0;$a<$hitung;$a++){
echo "<tr><td>".$unik2[$a]."</td>";	//angka
echo "<td>".$jumlah2[$a]."</td>";	//count
echo "<td>".$hh[$a]."</td>";	//fitnes
echo "<td>".$fit_efek[$a]."</td></tr>";}
echo "<tr><td>".$fit_slot_tot."</td><td>".$fit_efek_tot."</td><td>".$fit_total."</td></tr>";
echo "</table>";
}
?>
